package com.roc.androidlive.receiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

import com.roc.androidlive.service.MyIntentService;
import com.roc.androidlive.util.ServiceUtils;

public class MyReceiver extends BroadcastReceiver {

    private final String Tag = "MyReceiver";

    @Override
    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();
        Log.d(Tag, "the code run in MyReceiver, and the action is:" + action);
        boolean isRunning = ServiceUtils.isServiceRunning(context, MyIntentService.ServiceFullName);
        if (isRunning) {
            Log.d(Tag, "the service is running!");
        } else {
            Log.d(Tag, "the service is not running!");
            MyIntentService.startMyself(context);
        }
    }
}
